<?php

namespace App\Providers;

use App\Model\Cate;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // 获取所有的分类
        $cate = Cate::get();
        // 存放一级类变量
        $cateone = [];
        // 存放二级类变量
        $catetwo = [];
        // 遍历所有分类
        foreach ($cate as $k => $v) {
            if ($v->cate_pid == 0) {
                $cateone[$k] = $v;
                foreach ($cate as $m => $n) {
                    if ($v->id == $n->cate_pid) {
                        $catetwo[$k][$m] = $n;
                    }
                }
            }
        }

        view()->share('cateone',$cateone);
        view()->share('catetwo',$catetwo);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
